// 导出一个空对象，确保这个文件被视为模块
export {};

// 定义API响应类型
type APIResponse = any;

// 获取路线URL的函数，根据交通方式返回不同的URL
function getRouteUrl(transportMode: string, origin: string, destination: string): string {
  switch(transportMode) {
    case 'driving':
      return `http://localhost:3333/amap/maps/direction_driving?origin=${origin}&destination=${destination}`;
    case 'walking':
      return `http://localhost:3333/amap/maps/direction_walking?origin=${origin}&destination=${destination}`;
    case 'bicycling':
      return `http://localhost:3333/amap/maps/bicycling?origin=${origin}&destination=${destination}`;
    case 'transit':
    default:
      // 使用上海作为默认城市
      return `http://localhost:3333/amap/maps/direction_transit_integrated?origin=${origin}&destination=${destination}&city=上海&cityd=上海`;
  }
}

// 根据选择的交通方式、起点、终点获取路线信息
export const getRoute = async (origin: string, destination: string, mode: string = 'transit'): Promise<APIResponse> => {
  try {
    const url = getRouteUrl(mode, origin, destination);
    console.log('发起路线规划请求:', url);
    
    const response = await fetch(url, {
      headers: { 'Accept': 'application/json' }
    });

    return await response.json();
  } catch (error) {
    console.error('路线规划请求失败:', error);
    throw error;
  }
}; 